<?php
require_once("../../class2.php");
require_once(HEADERF);
require_once("./includes/require_all.php");
ramka("open");

$ganrers= array('Action','Adventure','Fighting','FPS','Fun','Hentai','Logical','Manager','MMORPG','Psycho','Quest','Racing','RPG','Simulator','Strategy','Sport','Tactical');
$toappg= $_GET['gname'];

?>
    <link rel="stylesheet" type="text/css" href="txtedit/jquery.cleditor.css" />
    <script type="text/javascript" src="txtedit/jquery.min.js"></script>
    <script type="text/javascript" src="txtedit/jquery.cleditor.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        $("#cgINFO").cleditor();
      });
    </script>
<?php
$userer=USERNAME;
if ($userer!='USERNAME' and in_array(USERNAME,$mods,true)) {

	if (isset($_POST['cgAPPROUVE'])){
		$cgNAME=mysql_real_escape_string($_POST['cgNAME']);
		$cgCOVER=mysql_real_escape_string($_POST['cgCOVER']);
		$cgYEAR=mysql_real_escape_string($_POST['cgYEAR']);
		$cgDEV=mysql_real_escape_string($_POST['cgDEV']);
		$cgINFO=mysql_real_escape_string($_POST['cgINFO']);
		$cgADD=mysql_real_escape_string($_POST['cgAddedBy']);
		$cgOS=mysql_real_escape_string($_POST['cgOS']);
		$cgOFF=mysql_real_escape_string($_POST['cgOFF']);
		$cgPROG=mysql_real_escape_string($_POST['cgPROG']);
		$cgRAM=mysql_real_escape_string($_POST['cgRAM']);
		$cgVGA=mysql_real_escape_string($_POST['cgVGA']);
		$cgHDS=mysql_real_escape_string($_POST['cgHDS']);
		$cgPATCH=intval(mysql_real_escape_string($_POST['cgPatch']));
		$cgYOUTUBE=mysql_real_escape_string($_POST['cgYOUTUBE']);
		
		$qqq = mysql_fetch_array(mysql_query("select * from gcs_main where prefix = '$toappg'"));
		$cg_cover = $qqq['Cover'];
		
		foreach ($_POST['cgganre'] as $cggn) {
			$cgGANRE.=$cggn."/";
		} $cgGANRE=mysql_real_escape_string(substr($cgGANRE,0,-1));
		foreach ($_POST['cgcat'] as $cgct) {
			$cgCAT.=$cgct."/";
		} $cgCAT=mysql_real_escape_string(substr($cgCAT,0,-1));
		if($cgPATCH != 0){
			foreach ($_POST['cgpatchfor'] as $cgpf) {
				$cgPATCHFOR.=$cgpf."/";
			} $cgPATCHFOR=mysql_real_escape_string(substr($cgPATCHFOR,0,-1));
			foreach ($_POST['cgpatching'] as $cging) {
				$cgPATCHING.=$cging."/";
			} $cgPATCHING=mysql_real_escape_string(substr($cgPATCHING,0,-1));
		}
		if (isset($_POST['cgAPPROUVE'])&&in_array(USERNAME,$mods,true)) {
			if($cg_cover != $cgCOVER){
				$sourcecode = file_get_contents("gts/covers/$cg_cover");
				file_put_contents("gts/covers/$cgCOVER", $sourcecode);
				unlink("gts/covers/$cg_cover");
			}
			mysql_query("UPDATE gcs_main SET Game = '$cgNAME', Ganre = '$cgGANRE', Year = '$cgYEAR', Translated = '$cgPATCH', Translating = '$cgPATCHING', TranslatedOn = '$cgPATCHFOR', AddedBy = '$cgADD', OfficialSite = '$cgOFF', Cover = '$cgCOVER', Developper = '$cgDEV', Platform = '$cgCAT', YouTube = '$cgYOUTUBE', Info = '$cgINFO', MinOS = '$cgOS', MinPROC = '$cgPROG', MinRAM = '$cgRAM', MinVGA = '$cgVGA', MinHDS = '$cgHDS', LastChange = now() where prefix = '$toappg'");
		}
	}

	if (isset($_GET['gname']) and in_array(USERNAME,$mods,true)) {
		$AP= mysql_fetch_array(mysql_query("SELECT * FROM gcs_main WHERE Prefix='$toappg'"));
		$plts= explode("/",$AP['Platform']);
		foreach ($plts as $val) {
			$chkdg[$val]="checked='yes'";
		}
		$grs= explode("/",$AP['Ganre']);
		foreach ($grs as $val) {
			$chkdg[$val]="checked='yes'";
		}
		$pf= explode("/",$AP['TranslatedOn']);
		foreach ($pf as $val) {
			$ch[$val]="checked='yes'";
		}
		$ping= explode("/",$AP['Translating']);
		foreach ($ping as $val) {
			$ching[$val]="checked='yes'";
		}
		$trans = intval($AP['Translated']);
		$addbuttn['name']= 'cgAPPROUVE';
		$addbuttn['value']= 'Одобри';
		$ifadd="?gname=".$_GET['gname'];
	}
	
	$classed= "class='tbox'";
	echo "
		<form name='input' action='gts-edit.php$ifadd' method='post'>
		<div class='forumheader3'>
		<h1 class='forumheader3 textWHITE'><center><INPUT type='text' name='cgNAME' value=\"$AP[Game]\" $classed></INPUT></center></h1>
		<table width=100% class='forumheader3'>
			<tr>
			<td class='forumheader3' width=30%><center><img src='gts/covers/$AP[Cover]' height=250px style='vertical-align:middle; margin-top:3px;'/><INPUT type='text' name='cgCOVER' $classed value='$AP[Cover]'><br>URL на картинката</INPUT></center><br></td>
			<td style='vertical-align:top;'>
				<table width=100%>
					<tr>
					<td class='forumheader3' width=30%> Година</td>
					<td class='forumheader'><INPUT type='text' name='cgYEAR' value='$AP[Year]' $classed></INPUT></td>
					</tr>
					<tr>
					<td class='forumheader3' width=30%> Разработчик</td>
					<td class='forumheader'><INPUT type='text' name='cgDEV' $classed value='$AP[Developper]'></INPUT></td>
					</tr>
					<tr>
					<td class='forumheader3' width=30%> Официален сайт</td>
					<td class='forumheader'><INPUT type='text' name='cgOFF' $classed value='$AP[OfficialSite]'></INPUT></td>
					</tr>
					<tr>
					<td class='forumheader3' width=30%> Платформа</td>
					<td class='forumheader'>
						<INPUT type='checkbox' name='cgcat[]' value='PC' onclick=toggle('minsys') $chkdg[PC]>PC</INPUT>
						<INPUT type='checkbox' name='cgcat[]' value='PS2' $chkdg[PS2]>PS2</INPUT>
						<INPUT type='checkbox' name='cgcat[]' value='PS3' $chkdg[PS3]>PS3</INPUT>
						<INPUT type='checkbox' name='cgcat[]' value='XBOX' $chkdg[XBOX]>XBOX</INPUT>
						<INPUT type='checkbox' name='cgcat[]' value='XBOX360' $chkdg[XBOX360]>XBOX360</INPUT>
					</td>
					</tr>				
					<tr>
					<td class='forumheader3' width=30%> Жанр</td>
					<td class='forumheader'>";

	foreach ($ganrers as $ganro) {
		echo "<INPUT type='checkbox' name='cgganre[]' value='$ganro' $chkdg[$ganro]>$ganro</INPUT>";
		if ($ganro=='Quest' or $ganro=='Sport') echo '<br>';
	}
		echo "</td></tr>
				<tr>
				<td class='forumheader3' width=30%> YouTube Трейлър</td>
				<td class='forumheader'>
					<INPUT type='text' name='cgYOUTUBE' value='$AP[YouTube]' $classed size=60></INPUT>
				</td>
				</tr>";
	switch($trans){
		case 0:
			echo "<tr><td class='forumheader3' width=30%> Пач</td>
				<td class='forumheader'>
				<INPUT type='radio' name='cgPatch' value='0' checked onclick='javascript:document.getElementById(\"patchfor\").style.visibility=\"hidden\"'>Няма
				<INPUT type='radio' name='cgPatch' value='2' onclick='javascript:document.getElementById(\"patchfor\").style.visibility=\"visible\"'>Има
				<INPUT type='radio' name='cgPatch' value='1' onclick='javascript:document.getElementById(\"patchfor\").style.visibility=\"visible\"'>В момента се прави
				</td></tr>
				<tr id='patchfor' style='visibility:hidden;'><td class='forumheader3' width=30%> Превод за</td>
				<td class='forumheader'>
				<input type='checkbox' name='cgpatchfor[]' value='PC' $ch[PC]>PC
				<input type='checkbox' name='cgpatchfor[]' value='PS2' $ch[PS2]>PS2
				<input type='checkbox' name='cgpatchfor[]' value='PS3' $ch[PS3]>PS3
				<input type='checkbox' name='cgpatchfor[]' value='XBOX' $ch[XBOX]>XBOX
				<input type='checkbox' name='cgpatchfor[]' value='XBOX360' $ch[XBOX360]>XBOX360
				</td></tr>"; break;
		case 1:
			echo "<tr><td class='forumheader3' width=30%> Пач</td>
				<td class='forumheader'>
				<INPUT type='radio' name='cgPatch' value='0' onclick='javascript:document.getElementById(\"patching\").style.display=\"none\";document.getElementById(\"patchfor\").style.display=\"none\";'>Няма
				<INPUT type='radio' name='cgPatch' value='2' onclick='javascript:document.getElementById(\"patchfor\").style.display=\"\";javascript:document.getElementById(\"patching\").style.display=\"none\";'>Има
				<INPUT type='radio' name='cgPatch' value='1' checked onclick='javascript:document.getElementById(\"patching\").style.display=\"\";javascript:document.getElementById(\"patchfor\").style.display=\"none\";'>В момента се прави
				</td></tr>
				<tr id='patching'><td class='forumheader3' width=30%> Превод за</td>
				<td class='forumheader'>
				<input type='checkbox' name='cgpatching[]' value='PC' $ching[PC]>PC
				<input type='checkbox' name='cgpatching[]' value='PS2' $ching[PS2]>PS2
				<input type='checkbox' name='cgpatching[]' value='PS3' $ching[PS3]>PS3
				<input type='checkbox' name='cgpatching[]' value='XBOX' $ching[XBOX]>XBOX
				<input type='checkbox' name='cgpatching[]' value='XBOX360' $ching[XBOX360]>XBOX360
				</td></tr>
				<tr id='patchfor'><td class='forumheader3' width=30%> Превод за</td>
				<td class='forumheader'>
				<input type='checkbox' name='cgpatchfor[]' value='PC' $ch[PC]>PC
				<input type='checkbox' name='cgpatchfor[]' value='PS2' $ch[PS2]>PS2
				<input type='checkbox' name='cgpatchfor[]' value='PS3' $ch[PS3]>PS3
				<input type='checkbox' name='cgpatchfor[]' value='XBOX' $ch[XBOX]>XBOX
				<input type='checkbox' name='cgpatchfor[]' value='XBOX360' $ch[XBOX360]>XBOX360
				</td></tr>
				<script>document.getElementById('patching').style.display='';document.getElementById('patchfor').style.display='none';</script>"; break;
		case 2:
			echo "<tr><td class='forumheader3' width=30%> Пач</td>
				<td class='forumheader'>
				<INPUT type='radio' name='cgPatch' value='0' onclick='javascript:document.getElementById(\"patchfor\").style.visibility=\"hidden\"'>Няма
				<INPUT type='radio' name='cgPatch' value='2' checked onclick='javascript:document.getElementById(\"patchfor\").style.visibility=\"visible\"'>Има
				<INPUT type='radio' name='cgPatch' value='1' onclick='javascript:document.getElementById(\"patchfor\").style.visibility=\"visible\"'>В момента се прави
				</td></tr>
				<tr id='patchfor' style='visibility:visible;'><td class='forumheader3' width=30%> Превод за</td>
				<td class='forumheader'>
				<input type='checkbox' name='cgpatchfor[]' value='PC' $ch[PC]>PC
				<input type='checkbox' name='cgpatchfor[]' value='PS2' $ch[PS2]>PS2
				<input type='checkbox' name='cgpatchfor[]' value='PS3' $ch[PS3]>PS3
				<input type='checkbox' name='cgpatchfor[]' value='XBOX' $ch[XBOX]>XBOX
				<input type='checkbox' name='cgpatchfor[]' value='XBOX360' $ch[XBOX360]>XBOX360
				</td></tr>"; break;
	}
	echo "</table>
	</td>
	</tr>
	</table>
	</div>
	<table width=100% class='forumheader3'>
	<tr>
	<td width=70%>
		<div class='forumheader3'> За играта</div>
		<div class='forumheader textGREY'><TEXTAREA name='cgINFO' id='cgINFO' $classed style='width:99%; min-height:180px;'>$AP[Info]</TEXTAREA></div>
		<div class='forumheader3'></div>
	</td>
	<td class='forumheader3' style='vertical-align:top;'>
		<div id='minsys' $divdisp>
		<div class='forumheader3'><center>Минимални изисквания</center></div>
		<center class='forumheader' style='font-weight:normal'>
			Операционна система:<INPUT type='text' name='cgOS' $classed value='$AP[MinOS]'></INPUT><br>
			Процесор:<br><INPUT type='text' name='cgPROG' $classed value='$AP[MinProc]'></INPUT><br>
			РАМ памет:<br><INPUT type='text' name='cgRAM' $classed value='$AP[MinRAM]'></INPUT><br>
			Видео карта:<br><INPUT type='text' name='cgVGA' $classed value='$AP[MinVGA]'></INPUT><br>
			Твърд диск:<br><INPUT type='text' name='cgHDS' $classed value='$AP[MinHDS]'></INPUT><br>
		</center>
		</div>
	</td>
	</tr>
	<tr>
		<td>
			Добавена от:<INPUT type='text' name='cgAddedBy' $classed value='$AP[AddedBy]'></INPUT>
		</td>
	</tr>
	</table>
	<center class='forumheader3'><input type='submit' name='$addbuttn[name]' value='$addbuttn[value]' class='button'/></center>
	</form>
	";
}
else echo "<div class='forumheader3 textRED'>Само регистрираните потребители могат да добавят игри в каталога.</div>";

ramka("close");
require_once(FOOTERF);
?>